import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:im_app/im/service/ImMessageService.dart';

import '../../pojo/Enums.dart';
import '../../util/DbUtil.dart';

final class MessageHistoryDayCubit extends Cubit<MessageHistoryDayState> {
  MessageHistoryDayCubit() : super(MessageHistoryDayState.loading());

  void loadData(int sessionId) async {
    var messageService = ImMessageService();
    var monthList = await messageService.getDaysForMonth(sessionId, DateTime.now(), 365 * 3);
    emit(MessageHistoryDayState.success(monthList));
  }
}

final class MessageHistoryDayState extends Equatable {

  final LoadingState state;
  final List<List<DateTime>> monthList;

  const MessageHistoryDayState._({
    this.state = LoadingState.loading,
    this.monthList = const <List<DateTime>>[],
  });

  const MessageHistoryDayState.loading() : this._();

  const MessageHistoryDayState.success(List<List<DateTime>> monthList)
      : this._(state: LoadingState.success, monthList: monthList);

  const MessageHistoryDayState.failure() : this._(state: LoadingState.failure);

  @override
  List<Object?> get props => [state, monthList];

}